Control algorithm